package com.example.sakurasay.security

import android.content.Context
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys

class EncryptionManager(context: Context) {

    private val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)

    private val sharedPreferences = EncryptedSharedPreferences.create(
        "secret_shared_prefs",
        masterKeyAlias,
        context,
        EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
        EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
    )

    fun encrypt(data: String): String {
        // This is a simplified example. In a real app, you would use the sharedPreferences
        // to store the encrypted data. Here, we'll just return a "crypted" version.
        return "crypted-" + data
    }

    fun decrypt(data: String): String {
        // This is a simplified example. In a real app, you would use the sharedPreferences
        // to retrieve the encrypted data. Here, we'll just remove the "crypted" prefix.
        if (data.startsWith("crypted-")) {
            return data.substring(8)
        }
        return data
    }
}